var app = getApp()
Page({
  data: {
    author: 'Lotus'
  },
  formSubmit: function (e) {
    var that = this;
    //var keyword = e.detail.value;  
    //console.log('form发生了submit事件，携带数据为：',e.detail.value);
    const params = e.detail.value
    if (!this.WxValidate.checkForm(e)) {
      const error = this.WxValidate.errorList[0]
      //console.log("param:" + error.param+"msg:" + error.msg)
      wx.showToast({
        title: error.msg,
        icon: 'error',
        duration: 2000
      })
      return false
    }
    var service = 'Balance.applyWithdraw';
    var amount = e.detail.value.amount;
    var wechat = e.detail.value.wechat;
    var mobile = e.detail.value.mobile;
    /*
     console.log("APIURL:" + app.globalData.APIURL)
     console.log("openId:" + app.globalData.openId)
         console.log("amount:" + amount)
         console.log("wechat:" + wechat)
         console.log("mobile:" + mobile)
 
 
     */
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, amount: amount, toAccount: wechat, name: mobile, tel: wechat },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        //debugger;
        //console.log("success:" + res.data.data)
        //debugger;
          if (!res.data.data.code) {
            wx.redirectTo({
              url: 'cashbox'
            })

          } else {
            wx.showToast({
              title: res.data.data.message,
              icon: 'error',
              duration: 2000
            })
          }

        },
      fail: function (res) {
        console.log("fail:" + res)
      },
    })

  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode = options.fromInviteCode;
    }
    app.appstart();

    that.WxValidate = app.WxValidate({
      amount: {
        required: true,
        minlength: 3,
      },
      wechat: {
        required: true,
        minlength: 1,
      },
      mobile: {
        required: true,
        minlength: 11,
      },
    }, {
        amount: {
          required: '请输入提现金额',
        },
        wechat: {
          required: '请输入微信号码',
        },
        mobile: {
          required: '请输入手机号',
        }

      })
  }
})